package com.zareal.ymcc.web.controller;

import com.zareal.ymcc.dto.SmsDto;
import com.zareal.ymcc.result.JSONResult;
import com.zareal.ymcc.service.IverifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IverifyCodeService verifyCodeService;

    // 将前端传过来的key用后端@PathVariable注解接受key
    @GetMapping("/imageCode/{key}")
    public JSONResult verifyCode(@PathVariable("key") String key) {

        // 将前端传过来的key获取64位Str
        String base64Str = verifyCodeService.getImgCode(key);
        return JSONResult.success(base64Str);
    }

    //    sendSmsCode
    @PostMapping("/sendSmsCode")
    public JSONResult getSmsMessage(@RequestBody SmsDto dto) {
        verifyCodeService.getSmsMessage(dto);
        return JSONResult.success("验证码已发送");
    }
}
